/*
 * After.cpp
 *
 *  Created on: May 13, 2012
 *      Author: kobe
 */

#include "After.h"

After::After(std::string input) :
		Proposition(AFTER) {
	std::string content(input, 2, input.size() - 2);
	size_t left, right;
	std::string sleft = getBracketContent(content, &left, &right);
	std::string ncontent(content, right + 2, content.size() - right - 2);
	std::string sright = getBracketContent(ncontent, &left, &right);
	mAction = createProposition(sleft);
	mProposition = createProposition(sright);
	if (!mAction->isAction() || mProposition->isAction()) {
		std::cout << "Parse error, update" << std::endl;
	}

}

After::After(Proposition* left, Proposition* right) :
		Proposition(AFTER) {
	mAction = left;
	mProposition = right;
	if (!mAction->isAction() || mProposition->isAction()) {
		std::cout << "Parse error, update" << std::endl;
	}
}

After::~After() {
	// TODO Auto-generated destructor stub
}

bool After::isAction() {
	return false;
}

Proposition *After::getAction() const {
	return mAction;
}

Proposition *After::getProposition() const {
	return mProposition;
}

bool After::compare(Proposition* p) {
	if (p->getPropName() != AFTER) {
		return false;
	} else {
		After *af = (After*) p;
		return mAction->compare(af->getAction())
				&& mProposition->compare(af->getProposition());
	}
}

std::string After::toString() {
	std::string result;
	result += "af{";
	result += mAction->toString();
	result += "}{";
	result += mProposition->toString();
	result += '}';
	return result;
}

std::string After::toLatex() {
	std::string s;
	s += "[";

	s += mAction->toLatex();
	s += "]";

	if (mProposition->getPropName() != ATOMIC
			&& mProposition->getPropName() != ACTION) {
		s += "(";
	}
	s += mProposition->toLatex();
	if (mProposition->getPropName() != ATOMIC
			&& mProposition->getPropName() != ACTION) {
		s += ")";
	}

	return s;
}

